<?php

$backgroundDir = "./images/background_image/";  
$sigCreated = false;
$formData = array();

$textOutlineChecked = ' checked="checked"';
if($_POST) {

  // save data
  $db = new SQLite3("db/db.sdb"); 
  
  if ( strlen($_POST['text_outline']) == '1' ) {
     $_POST['text_outline'] = 1;
    }
  else {
     $_POST['text_outline'] = 0;
    }
  $db->query("INSERT INTO character 
  (pool,realm,name,value1,value2,value3,value4,value5,background,color,text_outline,last_used) 
  VALUES 
  ('RG',
  '".$db->escapeString($_POST['realm'])."',
  '".$db->escapeString($_POST['name'])."',
  '".$db->escapeString($_POST['value1'])."',
  '".$db->escapeString($_POST['value2'])."',
  '".$db->escapeString($_POST['value3'])."',
  '".$db->escapeString($_POST['value4'])."',
  '".$db->escapeString($_POST['value5'])."',
  '".$db->escapeString($_POST['bg'])."',
  '".$db->escapeString($_POST['color'])."',
  '".$db->escapeString($_POST['text_outline'])."',
  '".time()."'
  );"); 

 $id = $db->lastInsertRowid();
 $db->close();
 
 // restore last form data
 $formData['realm'][$_POST['realm']] = ' selected = "selected"';
 $formData['value1'][$_POST['value1']] = ' selected = "selected"';
 $formData['value2'][$_POST['value2']] = ' selected = "selected"';
 $formData['value3'][$_POST['value3']] = ' selected = "selected"';
 $formData['value4'][$_POST['value4']] = ' selected = "selected"';
 $formData['value5'][$_POST['value5']] = ' selected = "selected"';
 $formData['name'] = $_POST['name'];
 $formData['color'] = $_POST['color'];
 $formData['bg'][$_POST['bg']] = ' checked="checked"';
 if($_POST['text_outline'] != 1) {
     $textOutlineChecked = ' checked="checked"';
   }
 
 $sigCreated = true;
 
 }
 

?>
<?php echo('<?xml version="1.0" encoding="UTF-8"?>'); ?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
 <title>WoW Signatur Generator</title>
 <meta name="keywords" content="WoW, Signatur, Generator, kanakana, World of Warcraft, Arsenal" />
 <meta name="description" content="Erstelle deine eigene WoW-Signatur - live aus dem Arsenal." />
 <script type="text/javascript" src="jscolor/jscolor.js"></script>
 <script type="text/javascript" src="niftycube.js"></script>
 <script type="text/javascript">
  window.onload=function(){
   Nifty("div#main");
  }
</script>
 <link href="css/main.css" rel="stylesheet" />
<!--[if IE]>
 <link href="css/ie.css" rel="stylesheet" />
<![endif]-->
<!--[if !IE]>-->
 <link href="css/notie.css" rel="stylesheet" />
<!--<![endif]-->

</head>

<body>

<div id="main">

<div id="head">
 <div id="head_inner"><img src="images/design/logo.png" alt="" /></div>
</div>

 <form action="./" method="post">
 <div id="data_input">
 <div id="data_input_inner">
  <div class="caption">Daten eingeben:</div>
  <label><span>Name: </span><input type="text" name="name" value="<?php echo $formData['name'] ?>"/></label>
  <label>   
   <span>RG-</span>
   <select name="realm">
    <option value="PvP-Realm"<?php echo $formData['realm']['PvP-Realm']; ?>>PvP-Realm</option>
    <option value="PvE-Realm"<?php echo $formData['realm']['PvE-Realm']; ?>>PvE-Realm</option>
   </select>
  </label>
   <?php
    for($i=0;$i<5;$i++) {
   ?>
  <label>
   <select name ="value<?php echo $i+1; ?>">
    <option value="">-Wert <?php echo $i+1; ?>-</option>
 	<option value="health"<?php echo $formData['value'.($i+1)]['health']; ?>>Gesundheit</option>	
	<option value="mana"<?php echo $formData['value'.($i+1)]['mana']; ?>>Mana/Wut/Energie</option>
    <option value="2on2_rating"<?php echo $formData['value'.($i+1)]['2on2_rating']; ?>>2vs.2 Arena</option>
	<option value="3on3_rating"<?php echo $formData['value'.($i+1)]['3on3_rating']; ?>>3vs.3 Arena</option>
	<option value="5on5_rating"<?php echo $formData['value'.($i+1)]['5on5_rating']; ?>>5vs.5 Arena</option>
	<option value="strength"<?php echo $formData['value'.($i+1)]['strength']; ?>>Stärke</option>	  
	<option value="agility"<?php echo $formData['value'.($i+1)]['agility']; ?>>Beweglichkeit</option>	  
	<option value="stamina"<?php echo $formData['value'.($i+1)]['stamina']; ?>>Ausdauer</option>  
	<option value="intellect"<?php echo $formData['value'.($i+1)]['intellect']; ?>>Intelligenz</option>  
	<option value="spirit"<?php echo $formData['value'.($i+1)]['spirit']; ?>>Willenskraft</option>
	<option value="meleeAp"<?php echo $formData['value'.($i+1)]['meleeAp']; ?>>Nahkampf Angriffskraft</option>
	<option value="meleeHit"<?php echo $formData['value'.($i+1)]['meleeHit']; ?>>Nahkampf Trefferchance</option>
	<option value="meleeArp"<?php echo $formData['value'.($i+1)]['meleeArp']; ?>>Nahkampf Rüstungsdurchschlag</option>
	<option value="meleeCrit"<?php echo $formData['value'.($i+1)]['meleeCrit']; ?>>Nahkampf Krit.</option>
	<option value="expertise"<?php echo $formData['value'.($i+1)]['expertise']; ?>>Waffenkundewertung</option>
	<option value="rangedAp"<?php echo $formData['value'.($i+1)]['rangedAp']; ?>>Fehrnkampf Angriffskraft</option>
	<option value="rangedHit"<?php echo $formData['value'.($i+1)]['rangedHit']; ?>>Fehrnkampf Trefferchance</option>
	<option value="rangedArp"<?php echo $formData['value'.($i+1)]['rangedArp']; ?>>Fehrnkampf Rüstungsdurchschlag</option>
	<option value="rangedCrit"<?php echo $formData['value'.($i+1)]['rangedCrit']; ?>>Fehrnkampf Krit.</option>
	<option value="spellPower"<?php echo $formData['value'.($i+1)]['spellPower']; ?>>Zaubermacht</option> 
	<option value="healingPower"<?php echo $formData['value'.($i+1)]['healingPower']; ?>>Heilungsbonus</option>
	<option value="spellHit"<?php echo $formData['value'.($i+1)]['spellHit']; ?>>Zuabertrefferchance</option>
	<option value="spellReduceResist"<?php echo $formData['value'.($i+1)]['spellReduceResist']; ?>>Zauberdurchschlag</option>
	<option value="spellCrit"<?php echo $formData['value'.($i+1)]['spellCrit']; ?>>Kritische Zaubertrefferchance</option>
	<option value="haste"<?php echo $formData['value'.($i+1)]['haste']; ?>>Geschwindigkeit / Haste</option>
	<option value="armor"<?php echo $formData['value'.($i+1)]['armor']; ?>>Rüstung</option>
	<option value="defense"<?php echo $formData['value'.($i+1)]['defense']; ?>>Verteidigung</option>
	<option value="avoid"<?php echo $formData['value'.($i+1)]['avoid']; ?>>Vermeidung %</option>
	<option value="dodge"<?php echo $formData['value'.($i+1)]['dodge']; ?>>Ausweichen %</option>
	<option value="parry"<?php echo $formData['value'.($i+1)]['parry']; ?>>Parrieren %</option>
	<option value="block"<?php echo $formData['value'.($i+1)]['block']; ?>>Blocken %</option>
	<option value="resilience"<?php echo $formData['value'.($i+1)]['resilience']; ?>>Abhärtung</option>  
    </select> 
  </label>
   <?php
     }
   ?>
  <div id="colors">
   <label><span>Farbe: </span><input type="text" name="color" class="color" value="<?php echo $formData['color']; ?>"/></label>
   <label><span id="textkontur">Textkontur: </span><input type="checkbox" value ="1" name="text_outline"<?php echo $textOutlineChecked; ?>/></label>
  </div> 
  <div class="sendbutton">
   <input type="submit" value="Signatur erstellen"/>
  </div>
 </div>
 </div>

 <div id="background_selection"> <!-- background selection -->
 <div id="background_selection_inner">
   <div class="caption">Hintergrund wählen:</div>
   <?php
    $fileArray = scandir($backgroundDir,1);
    foreach($fileArray as $file) {
	 if($file != "." && $file != "..") {
	 $file = substr($file,0,strlen($file)-4); //strip file extension
	 $imagePath = $backgroundDir.$file.".png";
   ?>
    <label class="background_selection"> 
	 <input class="background_radio" type="radio" name="bg" id="<?php echo $file; ?>" value="<?php echo $file; ?>"<?php echo $formData['bg'][$file]; ?> />
     <img src="<?php echo $imagePath; ?>" alt="" onclick="javascript:document.getElementById('<?php echo $file; ?>').checked = true; " />
	</label>
   <?php
      }
    }
   ?>
 </div>
 </div>

 </form> 

 <div id="bottom">
 <div id="bottom_inner">

<?php
if($sigCreated) {
   $imageUrl = "s".md5($id).".png";
// generate code when sig was created
?>
<img src="<?php echo $imageUrl ?>" alt="" /><br />
<div class="linkbox"> 
 <span>Direktlink:</span>
 <textarea rows="2" cols="60" onclick="this.select()">http://sig.kanakana.de/<?php echo $imageUrl; ?></textarea><br />
</div>
<div class="linkbox"> 
 <span>BBCode für Foren:</span>
 <textarea rows="2" cols="60" onclick="this.select()">[url=http://sig.kanakana.de/][img]http://sig.kanakana.de/<?php echo $imageUrl; ?>[/img][/url]</textarea><br />
</div>
<div class="linkbox">
 <span>HTML Code:</span>
 <textarea rows="2" cols="60" onclick="this.select()"><a href="http://sig.kanakana.de/"><img src="http://sig.kanakana.de/<?php echo $imageUrl; ?>" alt="" /></a></textarea><br />
</div>
 <?php
  }
?>
 </div>
 </div> 

 </div> 

 <div id="footer">
 </div>
 </body>
 
</html>